package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.park_bean.bean.AddMonthCarBean;
import com.xinfu.newproject.bean.park_bean.bean.CheckMonthParkBean;
import com.xinfu.newproject.bean.park_bean.bean.FeeListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetMonthCarListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetParkingBean;
import com.xinfu.newproject.bean.park_bean.bean.MonthCarPayBean;
import com.xinfu.newproject.bean.park_bean.bean.PaymentsBean;
import com.xinfu.newproject.bean.park_bean.bean.TempPayBean;
import com.xinfu.newproject.bean.park_bean.body.AddMonthCarBody;
import com.xinfu.newproject.bean.park_bean.body.AppIntoPayBody;
import com.xinfu.newproject.bean.park_bean.body.CheckMonthParkBody;
import com.xinfu.newproject.bean.park_bean.body.FeeListBody;
import com.xinfu.newproject.bean.park_bean.body.GetMonthCarListBody;
import com.xinfu.newproject.bean.park_bean.body.GetParkingBody;
import com.xinfu.newproject.bean.park_bean.body.PaymentsBody;
import com.xinfu.newproject.bean.park_bean.body.TempPayBody;
import com.xinfu.newproject.bean.paycost.bean.ComputeParkingBean;
import com.xinfu.newproject.bean.paycost.body.ComputeParkingBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.park.ParkingModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class ParkingPresenter {
    private IView.IParkingView mIParkingView;
    private IView.IAppIntoPayView mIAppIntoPayView;
    private IView.ITempPayView mITempPayView;

    private ParkingModel mParkingModel;

    public ParkingPresenter(IView.IParkingView iParkingView) {
        this.mIParkingView = iParkingView;
        mParkingModel = new ParkingModel();
    }

    public ParkingPresenter(IView.IAppIntoPayView iAppIntoPayView) {
        this.mIAppIntoPayView = iAppIntoPayView;
        mParkingModel = new ParkingModel();
    }

    public ParkingPresenter(IView.ITempPayView iTempPayView) {
        this.mITempPayView = iTempPayView;
        mParkingModel = new ParkingModel();
    }

    /**
     * 查询停车场
     */
    public void getParkingLot() {
        mIParkingView.showProgress();
        GetParkingBody getParkingBody = new GetParkingBody(mIParkingView.header(), mIParkingView.userId());

        mParkingModel.getParking(getParkingBody, new MyCallBack<GetParkingBean>() {
            @Override
            public void onSuccess(GetParkingBean getParkingBean) {
                mIParkingView.hideProgress();
                if (getParkingBean.isSuccess()) {
                    mIParkingView.getMsg(getParkingBean);
                } else {
                    mIParkingView.showToast(getParkingBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });


    }

    /**
     * 续费记录
     */
    public void feeList() {
//        mIParkingView.showProgress();
        FeeListBody feeListBody = new FeeListBody(mIParkingView.header(), mIParkingView.carId());

        mParkingModel.feeList(feeListBody, new MyCallBack<FeeListBean>() {
            @Override
            public void onSuccess(FeeListBean feeListBean) {
//                mIParkingView.hideProgress();
                if (feeListBean.isSuccess()) {
                    mIParkingView.getMsg(feeListBean);
                } else {
                    mIParkingView.showToast(feeListBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
//                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });


    }


    /**
     * 根据车场id和车牌号检查车辆信息
     */
    public void checkMonthParkCar() {
        mIParkingView.showProgress();
        CheckMonthParkBody checkMonthParkBody = new CheckMonthParkBody(mIParkingView.header(), mIParkingView.userId(), mIParkingView.parkInfoId(), mIParkingView.carId(), mIParkingView.carType());

        mParkingModel.checkMonthParkCar(checkMonthParkBody, new MyCallBack<CheckMonthParkBean>() {
            @Override
            public void onSuccess(CheckMonthParkBean checkMonthParkBean) {
                mIParkingView.hideProgress();
                if (checkMonthParkBean.isSuccess()) {
                    mIParkingView.getMsg(checkMonthParkBean);
                } else {
                    mIParkingView.showToast(checkMonthParkBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });


    }

    /**
     * 添加月卡车
     */
    public void addMonthCar() {
        mIParkingView.showProgress();
        AddMonthCarBody addMonthCarBody = new AddMonthCarBody(mIParkingView.header()
                , mIParkingView.userId()
                , mIParkingView.projectId()
                , mIParkingView.exclusiveFlag()
                , mIParkingView.parkInfoId()
                , mIParkingView.carId()
                , mIParkingView.monthCarType()
                , mIParkingView.roomId()
                , mIParkingView.owner()
                , mIParkingView.mobile()
                , mIParkingView.images()
                , mIParkingView.remark()
                , mIParkingView.idType()
                , mIParkingView.carType()
                , mIParkingView.filed1());

        mParkingModel.addMonthCar(addMonthCarBody, new MyCallBack<AddMonthCarBean>() {
            @Override
            public void onSuccess(AddMonthCarBean addMonthCarBean) {
                mIParkingView.hideProgress();
                if (addMonthCarBean.isSuccess()) {
                    mIParkingView.getMsg(addMonthCarBean);
                } else {
                    if (addMonthCarBean.getResult() != null) {
                        mIParkingView.showToast(addMonthCarBean.getResult());
                    } else {
                        mIParkingView.showToast(addMonthCarBean.getMessage());
                    }
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });


    }

    /**
     * 根据用户id查询月卡车列表
     */
    public void getMonthCarList() {
        mIParkingView.showProgress();
        GetMonthCarListBody getMonthCarListBody = new GetMonthCarListBody(mIParkingView.header()
                , mIParkingView.userId()
                , mIParkingView.carType());

        mParkingModel.getMonthCarList(getMonthCarListBody, new MyCallBack<GetMonthCarListBean>() {
            @Override
            public void onSuccess(GetMonthCarListBean getMonthCarListBean) {
                mIParkingView.hideProgress();
                if (getMonthCarListBean.isSuccess()) {
                    mIParkingView.getMsg(getMonthCarListBean);
                } else {
                    mIParkingView.showToast(getMonthCarListBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });
    }

    /**
     * 支付方式查询
     */
    public void payments() {
//        mIParkingView.showProgress();
        PaymentsBody paymentsBody = new PaymentsBody(mIParkingView.header()
                , mIParkingView.id()
                , mIParkingView.startTime()
                , mIParkingView.orderId());

        mParkingModel.payments(paymentsBody, new MyCallBack<PaymentsBean>() {
            @Override
            public void onSuccess(PaymentsBean paymentsBean) {
//                mIParkingView.hideProgress();
                if (paymentsBean.isSuccess()) {
                    mIParkingView.getMsg(paymentsBean);
                } else {
                    mIParkingView.showToast(paymentsBean.getMessage());
                }
//                mIParkingView.showToast(new Gson().toJson(paymentsBean));
            }

            @Override
            public void onError(String header, String message) {
//                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });
    }

    /**
     * 停车缴费支付
     */
    public void appIntoPay() {
        mIAppIntoPayView.showProgress();
        AppIntoPayBody appIntoPayBody = new AppIntoPayBody(mIAppIntoPayView.header()
                , mIAppIntoPayView.userId()
                , mIAppIntoPayView.carId()
                , mIAppIntoPayView.carType()
                , mIAppIntoPayView.parkCarId()
                , mIAppIntoPayView.startTime()
                , mIAppIntoPayView.num()
                , mIAppIntoPayView.payAmount()
                , mIAppIntoPayView.payMemo()
                , mIAppIntoPayView.mobile()
                , mIAppIntoPayView.projectId()
                , mIAppIntoPayView.tenantId());

        mParkingModel.appIntoPay(appIntoPayBody, new MyCallBack<MonthCarPayBean>() {
            @Override
            public void onSuccess(MonthCarPayBean monthCarPayBean) {
                mIAppIntoPayView.hideProgress();
                if (monthCarPayBean.isSuccess()) {
                    mIAppIntoPayView.getMsg(monthCarPayBean);
                } else {
                    mIAppIntoPayView.showToast(monthCarPayBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIAppIntoPayView.hideProgress();
                mIAppIntoPayView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIAppIntoPayView.closeDispose(disposable);
            }
        });
    }

    /**
     * 查询临停
     */
    public void computeParkingCar() {
        mIParkingView.showProgress();
        ComputeParkingBody computeParkingBody = new ComputeParkingBody(mIParkingView.licensePlate());

        mParkingModel.ComputeParkingFee(computeParkingBody, new MyCallBack<ComputeParkingBean>() {
            @Override
            public void onSuccess(ComputeParkingBean computeParkingBean) {
                mIParkingView.hideProgress();
                if (computeParkingBean.isSuccess()) {
                    mIParkingView.getMsg(computeParkingBean);
                } else {
                    mIParkingView.showToast(computeParkingBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
                mIParkingView.hideProgress();
                mIParkingView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIParkingView.closeDispose(disposable);
            }
        });
    }


    /**
     * 临停支付
     */
    public void tempPay() {
        mITempPayView.showProgress();
        TempPayBody tempPayBody = new TempPayBody(mITempPayView.header(), mITempPayView.userId(), mITempPayView.mobile(), mITempPayView.carType(), mITempPayView.carId(), mITempPayView.PKName(), mITempPayView.payAmount(), mITempPayView.PKID(), mITempPayView.tempOrderNo());

        mParkingModel.tempPay(tempPayBody, new MyCallBack<TempPayBean>() {
            @Override
            public void onSuccess(TempPayBean tempPayBean) {
                mITempPayView.hideProgress();
                if (tempPayBean.isSuccess()) {
                    mITempPayView.getMsg(tempPayBean);
                } else {
                    mITempPayView.showToast(tempPayBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
                mITempPayView.hideProgress();
                mITempPayView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mITempPayView.closeDispose(disposable);
            }
        });


    }

}
